namespace ghost{
    export class SliderInput extends Laya.Box {
        public slider: Laya.HSlider;
        public input: Laya.TextInput
        public lab: Laya.Text;
        constructor(label: string = "设置", min: number = 0, max: number = 100, value: number = 0) {
            super();
            let s = this;
            s.lab = new Laya.Text;
            s.lab.fontSize = 20;
            s.lab.color = "#000000";
            s.lab.width = 100;
            s.addChild(s.lab);
            s.input = new Laya.TextInput;
            s.input.color = "#000000";
            s.input.fontSize = 20;
            s.input.width = 100;
            s.addChild(s.input);
            s.slider = new Laya.HSlider;
            s.slider.width = 300;
            s.slider.height = 32;
            s.slider.changeHandler = Laya.Handler.create(s, s.sliderChange, null, false);
            s.addChild(s.slider);
            s.input.restrict = "0-9.";
            s.slider.showLabel = false;
            s.setRange(min, max, value);
            s.setLabel(label);
            s.validDisplay();
            s.input.on(Laya.Event.INPUT, s, s.textChange);
        }
        private textChange(e: Laya.Event): void {
            let s = this;
            s.slider.value = Number(s.input.text);
        }
        private sliderChange(): void {
            let s = this;
            s.input.text = s.slider.value + "";
            if (s.hasListener(Laya.Event.CHANGE))
                s.event(Laya.Event.CHANGE, s);
        }
        public get value(): number {
            return this.slider.value;
        }
        public setRange(min: number, max: number, value: number): void {
            let s = this;
            s.slider.setSlider(min, max, value);
            s.input.text = value + "";
        }
        public setLabel(val: string): void {
            this.lab.text = val;
        }
        public validDisplay(): void {
            let s = this;
            s.input.x = s.lab.x + s.lab.width;
            s.slider.x = s.input.x + s.input.width;
            s.width = s.slider.x + s.slider.width * s.slider.scaleX;
        }
    }
}
